package bg.btanev.eightyfour.client.view;

import bg.btanev.eightyfour.client.composite.BasicTabComposite;
import bg.btanev.eightyfour.client.presenter.TargetTabPresenter.TargetTabDisplay;

import com.google.gwt.event.logical.shared.HasBeforeSelectionHandlers;
import com.google.gwt.event.logical.shared.HasSelectionHandlers;
import com.google.gwt.user.client.ui.DecoratedTabBar;
import com.google.gwt.user.client.ui.HasWidgets;
import com.google.gwt.user.client.ui.Widget;

public class TargetTabView extends BasicTabComposite implements TargetTabDisplay {

	public TargetTabView() {
		super();
	}

	@Override
	public HasBeforeSelectionHandlers<Integer> getBeforeSelectionActionMenuHandlers() {
		return getActionsMenuTabBar();
	}

	@Override
	public HasSelectionHandlers<Integer> getSelectionActionMenuHandlers() {
		return getActionsMenuTabBar();
	}

	@Override
	public Widget asWidget() {
		return this;
	}

	@Override
	public HasWidgets getActionDataContainer() {
		return super.getActionDataCenterPanel();
	}

	@Override
	public HasWidgets getDataContainer() {
		return super.getDataPanel();
	}

	@Override
	public void addActionMenus(String[] actionMenus) {
		DecoratedTabBar actionMenusContainer = getActionsMenuTabBar();
		int oldMenusCount = actionMenusContainer.getTabCount();
		for (int i = 0; i < oldMenusCount; i++) {
			actionMenusContainer.removeTab(i);
		}

		if (actionMenus != null && actionMenus.length > 0) {
			for (int i = 0; i < actionMenus.length; i++) {
				actionMenusContainer.addTab(actionMenus[i]);
			}
		}
	}
}
